<?xml version="1.0" encoding="UTF-8"?>
<%@page contentType="text/html; charset=UTF-8" %>
<%
	String action = request.getParameter("action");
	String id = request.getParameter("id");

	if ("ADD".equals(action)) {
		Author a = new Author();
		a.setFirstName("");
		a.setLastName("");
		
		SessionUtil.setAuthor(session, a);
		
	} else if ("EDIT".equals(action)) {
		Session hSession = HibernateUtil.getSessionFactory().getCurrentSession();
		Author a = (Author) hSession.get(Author.class, Long.valueOf(id));
		
		SessionUtil.setAuthor(session, a);
	}

	Author author = SessionUtil.getAuthor(session);
	Boolean creation = (author.getId() == null);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
	<% if (creation) { %>
	<title>Bookstore :: Back office :: Ajouter un auteur</title>
	<% } else { %>
	<title>Bookstore :: Back office :: Modifier un auteur</title>
	<% } %>
	<%@include file="include.jsp" %>
</head>

<body>
	<%@include file="commun.jsp" %>
	
	<div class="contenuAvecMenu">
		<% if (creation) { %>
		<h2>Ajouter un auteur</h2>
		<% } else { %>
		<h2>Modifier un auteur</h2>
		<% } %>
		<form method="post" action="SaveAuthor.do">
			<div class="boite bleue">
				<p>
					<label for="lastName">Nom</label>
					<input type="text" id="lastName" name="lastName" value="<%=author.getLastName()%>" />
				</p>
				
				<p>
					<label for="firstName">Prenom</label>
					<input type="text" id="firstName" name="firstName" value="<%=author.getFirstName()%>" />
				</p>
				
				<input type="submit" value="Sauvegarder" />
			</div>
		</form>
	</div>
</body>
</html>
